use craftdig_math::Direction;

use crate::block::msgs::*;
use crate::block::BlkId;
use crate::message::*;

/// Silly behavior that just prints a log message, for debugging purposes.
pub struct LogOnPlaceBehavior;

impl MsgAccept for LogOnPlaceBehavior {
    type Msg = OnPlaceMessage;
    fn accept(&self, inst: &mut BlockContext, _msg: &Self::Msg) -> Result<(), BehaviorError> {
        eprintln!("MSG HANDLER: block placed at {:?}", inst.pos());

        // Check the block below us.
        let below_id = inst
            .get_neighbor_blkid(Direction::Down)
            .unwrap_or(BlkId::zero());

        // If it's empty then say that we should fall.
        if below_id.is_zero() {
            eprintln!("WE SHOULD BE FALLING");
        }

        Ok(())
    }
}

/// Silly behavior that just prints a log message, for debugging purposes.
pub struct LogOnUpdateBehavior;

impl MsgAccept for LogOnUpdateBehavior {
    type Msg = NeighborUpdateMessage;
    fn accept(&self, inst: &mut BlockContext, msg: &Self::Msg) -> Result<(), BehaviorError> {
        eprintln!(
            "MSG HANDLER: block updated at {:?} (from {:?})",
            inst.pos(),
            msg.neighbor_pos()
        );
        Ok(())
    }
}
